<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/ZendSkeletonApplication for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Application\Controller;

use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Application\Form\AbonnementForm;
use Application\Model\abonnement\Abonnement;
use Zend\Http\Header\SetCookie;
use Zend\Session\Container;

class IndexController extends AbstractActionController
{
	protected $abonnementTable;
	public function indexAction()
    {
    date_default_timezone_set('UTC');	
   /* 	$user_session = new Container('user');
    	
    	$user_session->language = 'fr_FR';
    	 
    	return $this->redirect()->toRoute('contact',
    			array('controller'=>'Contact',
    					'action' => 'contact',
    					
    	
    			));*/
    	 
    	$cookie = new SetCookie('test', 'france', time() + 365 * 60 * 60 * 24); // now + 1 year
    	$response = $this->getResponse()->getHeaders();
    	$response->addHeader($cookie);
    	//echo $cookie->getValue();
    	
    	
    	return new ViewModel();
    }
    
    public function lamisaenimageAction(){
    	return new ViewModel();
    }
    
    public function abonnementAction(){

    	$form  = new AbonnementForm();
    	 
    	$request = $this->getRequest();
    	if ($request->isPost()) {
    		 
    		$sample = new Abonnement();
    		$form->setInputFilter($sample->getInputFilter());
    		$form->setData($request->getPost());

    		if ($form->isValid()) {

    			$datas = $form->getData() ;
    			$datas->exchangeArray($form->getData());
    	
    			$email  = $datas['email'];
    			$action  = $datas['action'];
    	
    			return new ViewModel(array(
    					'email' =>$email,
    					'form' => $form,
    					'resultat' =>'1',    	
    			));
	
    		}else {
    			
    		}
    	}
    	 
    	return array(
    			'form' => $form
    	);
    
    	return new ViewModel();
    }
    /**
     * 
     * @return \Zend\View\Model\ViewModel
     * 
     * affiche les details sur les services LAMISA
     * 
     */
    public function servicesAction(){
    	return new ViewModel();
    }
    
    /**
     * 
     * @return \Zend\View\Model\ViewModel
     * 
     * permet d'aficher les  details sur les annonces recrutement
     * 
     */
    public function recrutementAction(){
    	return new ViewModel();
    }
    
    public function getServiceTable()
    {
    	if (!$this->abonnementTable) {
    		$sm = $this->getServiceLocator();
    		$config = $sm->get('config');
    		$config = $config['db'];
    		$dbAdapter = new DbAdapter($config);
    		//return $dbAdapter;
    		$table = new ServicesTable($dbAdapter);
    		//$this->userTable = $sm->get($table);
    		$this->abonnementTable = $table;
    	}
    	return $this->abonnementTable;
    }
    
}
